package de.akabahn.ebd.ablfstrg.anlage;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Peter Eimann
 */
public class TfzInfo {

	private String tfz;
	private List<Integer> speedList;

	/**
	 * @param tfzInfoString
	 * @return
	 */
	public static TfzInfo unmarshal(String tfz, String tfzInfoString) {
		// Response-Format: OK (<V5>,<V10>,<V15>.....<V240>|TYP|HG|PFEI|TUER|ABV)
		if (tfzInfoString != null && tfzInfoString.startsWith("OK (")) {
			String[] segments = tfzInfoString.substring(4, tfzInfoString.length() - 1).split("\\|");
			TfzInfo tfzInfo = new TfzInfo();
			tfzInfo.setTfz(tfz);
			List<Integer> speedList = new ArrayList<Integer>();
			speedList.add(0);
			for (String speed : segments[0].split(",")) {
				speedList.add(Integer.decode(speed));
			}
			tfzInfo.setSpeedList(speedList);

			return tfzInfo;
		}

		return null;
	}

	/**
	 * @return the tfz
	 */
	public String getTfz() {
		return tfz;
	}

	/**
	 * @return the speedList
	 */
	public List<Integer> getSpeedList() {
		return speedList;
	}

	/**
	 * @param tfz the tfz to set
	 */
	void setTfz(String tfz) {
		this.tfz = tfz;
	}

	/**
	 * @param speedList the speedList to set
	 */
	void setSpeedList(List<Integer> speedList) {
		this.speedList = speedList;
	}
}
